
#include <string.h>
#include <stdint.h>
#include <stdlib.h>
#include"system_init.h"
#include "CheckFile.h"


void initS19Data(str_S19LineData *str_S19LineData){
    str_S19LineData->address = 0;
    str_S19LineData->checkSumCode = 0;
    str_S19LineData->count = 0;
    memset(str_S19LineData->data,0x00,sizeof(str_S19LineData->data));
    str_S19LineData->dataLen = 0;
    str_S19LineData->Type = S19_TYPE_S_UNKNOW;
}
void initHEXData(str_HEXLineData *HEXLineData){
    HEXLineData->address = 0;
    HEXLineData->baseAddr = 0;
    HEXLineData->checkCode = 0;
    memset(HEXLineData->data,0x00,sizeof(HEXLineData->data));
    HEXLineData->dataLen = 0;
    HEXLineData->Type = HEX_UNKNOW;
}

char ConvertHexChar(char ch)
{
    if((ch >= '0') && (ch <= '9'))
        return (ch-0x30);
    else if((ch >= 'A') && (ch <= 'F'))
        return ((ch-'A')+10);
    else if((ch >= 'a') && (ch <= 'f'))
        return ((ch-'a')+10);
    else return (-1);
}

S19ErrCode validateS19String(const char* s19String, unsigned int strLen,str_S19LineData *S19LineData){
    uint16_t i = 0;
    const char s19TypeTable[8][3] = {"S0","S1","S2","S3","S5","S7","S8","S9"};
    uint8_t transformTemp[8] = {0};
    uint8_t countSize = 0;
    const char *strP = NULL;
    uint16_t checkSizeTemp = 0;
    uint8_t getCountLoopCount = 0;
    strP = s19String;
    initS19Data(S19LineData);
    transformTemp[0] = *strP;
    
    if(!strcmp((const char*)transformTemp,"S")){
        memset(transformTemp,0x00,sizeof(transformTemp));
        memcpy(transformTemp,strP,2);
        for (i = 0; i < 8; i++)
        {
            if(!strcmp((const char*)transformTemp,s19TypeTable[i])){
                S19LineData->Type = (em_S19Type)i;
                break;
            }
        }
        if(i == 8){
            S19LineData->Type = S19_TYPE_S_UNKNOW;
            return S19_TYPE_ERROR;
        }
        strP+=2;
        // memset(transformTemp,0x00,sizeof(transformTemp));
        // memcpy(transformTemp,strP,2);
        countSize =  ConvertHexChar(*strP)<<4;
        countSize |= ConvertHexChar(*(++strP));
        if(countSize > 0 && countSize<128){
            S19LineData->count = countSize;
            checkSizeTemp += (S19LineData->count) & 0xff;
        }else{
            return S19_LENGHT_ERROR;
        }
        //addr
        if(S19LineData->Type == S19_TYPE_S0){
            S19LineData->address = 0;
            strP+=4;
            getCountLoopCount = S19LineData->count-3;
        }else if(S19_TYPE_S1 == S19LineData->Type || S19_TYPE_S5 == S19LineData->Type || S19_TYPE_S9 == S19LineData->Type){
            
            S19LineData->address = (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
            S19LineData->address <<= 8;
            S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
            
            checkSizeTemp += (S19LineData->address >>8) & 0xff;
            checkSizeTemp += (S19LineData->address) & 0xff;
            getCountLoopCount = S19LineData->count-3;

        }else if(S19_TYPE_S2 == S19LineData->Type || S19_TYPE_S8 == S19LineData->Type){

            S19LineData->address = (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
            S19LineData->address <<= 8;
            S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
            S19LineData->address <<= 8;
            S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
    
            checkSizeTemp += (S19LineData->address >>16) & 0xff;
            checkSizeTemp += (S19LineData->address >>8) & 0xff;
            checkSizeTemp += (S19LineData->address) & 0xff;
            getCountLoopCount = S19LineData->count-4;

        }else if (S19_TYPE_S3 == S19LineData->Type || S19_TYPE_S7 == S19LineData->Type){

            S19LineData->address = (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
            S19LineData->address <<= 8;
            S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
            S19LineData->address <<= 8;
            S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
            S19LineData->address <<= 8;
            S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            S19LineData->address |= ConvertHexChar(*(++strP));
    
            checkSizeTemp += (S19LineData->address >>24) & 0xff;
            checkSizeTemp += (S19LineData->address >>16) & 0xff;
            checkSizeTemp += (S19LineData->address >>8) & 0xff;
            checkSizeTemp += (S19LineData->address) & 0xff;
            getCountLoopCount = S19LineData->count-5;
        }
        for (i = 0; i < getCountLoopCount; i++)
        {
            S19LineData->data[i] = ConvertHexChar(*(++strP))<<4;
            S19LineData->data[i] |= ConvertHexChar(*(++strP));
            checkSizeTemp += S19LineData->data[i];
        }
        S19LineData->dataLen = getCountLoopCount;
        S19LineData->checkSumCode = (ConvertHexChar(*(++strP))<<4);
        S19LineData->checkSumCode |= ConvertHexChar(*(++strP));
        
        if(S19LineData->checkSumCode != (0xff - (checkSizeTemp & 0xff))){
            fprintf(USART2_STREAM,"--s19 check error:%x,%x\r\n",S19LineData->checkSumCode,checkSizeTemp);
            return S19_VERIFY_ERROR;
            
        }else{
            return S19_NO_ERROR;
        }
    }else{
        return S19_FORMAT_ERROR;
    }
}

// S19ErrCode validateS19String(const char* s19String, unsigned int strLen,str_S19LineData *S19LineData){
//     uint16_t i,j;
//     uint16_t readSize = 0;
//     const char s19TypeTable[8][3] = {"S0","S1","S2","S3","S5","S7","S8","S9"};
//     uint8_t transformTemp[8] = {0};
//     uint8_t addrSize = 0;
//     uint8_t countSize = 0;
//     const char *strP = NULL;
//     uint16_t checkSizeTemp = 0;
//     uint8_t getCountLoopCount = 0;
//     strP = s19String;
//     initS19Data(S19LineData);
//     transformTemp[0] = *strP;
    
//     if(!strcmp((const char*)transformTemp,"S")){
//         memset(transformTemp,0x00,sizeof(transformTemp));
//         memcpy(transformTemp,strP,2);
//         for (i = 0; i < 8; i++)
//         {
//             if(!strcmp((const char*)transformTemp,s19TypeTable[i])){
//                 S19LineData->Type = (em_S19Type)i;
//                 break;
//             }
//         }
//         if(i == 8){
//             S19LineData->Type = S19_TYPE_S_UNKNOW;
//             return S19_TYPE_ERROR;
//         }
//         strP+=2;
//         // memset(transformTemp,0x00,sizeof(transformTemp));
//         // memcpy(transformTemp,strP,2);
//         countSize =  ConvertHexChar(*strP)<<4;
//         countSize |= ConvertHexChar(*(++strP));
//         if(countSize > 0 && countSize<128){
//             S19LineData->count = countSize;
//         }else{
//             return S19_LENGHT_ERROR;
//         }
//         //addr
//         if(S19LineData->Type == S19_TYPE_S0){
//             S19LineData->address = 0;
//         }else if(S19_TYPE_S1 == S19LineData->Type || S19_TYPE_S5 == S19LineData->Type || S19_TYPE_S9 == S19LineData->Type){
            
//             S19LineData->address = (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
//             S19LineData->address <<= 8;
//             S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
            
//             checkSizeTemp += (S19LineData->address >>8) & 0xff;
//             checkSizeTemp += (S19LineData->address) & 0xff;
//             getCountLoopCount = S19LineData->count-3;

//         }else if(S19_TYPE_S2 == S19LineData->Type || S19_TYPE_S8 == S19LineData->Type){

//             S19LineData->address = (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
//             S19LineData->address <<= 8;
//             S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
//             S19LineData->address <<= 8;
//             S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
    
    
//             checkSizeTemp += (S19LineData->address >>16) & 0xff;
//             checkSizeTemp += (S19LineData->address >>8) & 0xff;
//             checkSizeTemp += (S19LineData->address) & 0xff;
//             getCountLoopCount = S19LineData->count-4;

//         }else if (S19_TYPE_S3 == S19LineData->Type || S19_TYPE_S7 == S19LineData->Type){

//             S19LineData->address = (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
//             S19LineData->address <<= 8;
//             S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
//             S19LineData->address <<= 8;
//             S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
//             S19LineData->address <<= 8;
//             S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
//             S19LineData->address |= ConvertHexChar(*(++strP));
    
//             checkSizeTemp += (S19LineData->address >>24) & 0xff;
//             checkSizeTemp += (S19LineData->address >>16) & 0xff;
//             checkSizeTemp += (S19LineData->address >>8) & 0xff;
//             checkSizeTemp += (S19LineData->address) & 0xff;
//             getCountLoopCount = S19LineData->count-5;
//         }
//         for (i = 0; i < getCountLoopCount; i++)
//         {
//             S19LineData->data[i] = ConvertHexChar(*(++strP))<<4;
//             S19LineData->data[i] |= ConvertHexChar(*(++strP));
//             checkSizeTemp += S19LineData->data[i];
//         }
        
//         S19LineData->checkSumCode = (ConvertHexChar(*(++strP))<<4);
//         S19LineData->checkSumCode |= ConvertHexChar(*(++strP));
//         if(S19LineData->checkSumCode != (0xff - (checkSizeTemp & 0xff))){
//             return S19_VERIFY_ERROR;
            
//         }else{
//             return S19_NO_ERROR;
//         }
//     }else{
//         return S19_FORMAT_ERROR;
//     }
//     return 0;
// }

HEXErrCode validateHEXString(const char* hexString, unsigned int strLen,str_HEXLineData *HEXLineData){
    uint16_t i = 0;
    uint8_t transformTemp[8] = {0};
    uint8_t countSize = 0;
    const char *strP = NULL;
    uint16_t checkSizeTemp = 0;
    strP = hexString;
    initHEXData(HEXLineData);
    transformTemp[0] = *strP;
    
    if(!strcmp((const char*)transformTemp,":")){
        strP++;
        countSize =  ConvertHexChar(*strP)<<4;
        countSize |= ConvertHexChar(*(++strP));
        HEXLineData->dataLen = countSize;
        checkSizeTemp = countSize;

        HEXLineData->address = (ConvertHexChar(*(++strP))<<4);
        HEXLineData->address |= ConvertHexChar(*(++strP));
        HEXLineData->address <<= 8;
        HEXLineData->address |= (ConvertHexChar(*(++strP))<<4);
        HEXLineData->address |= ConvertHexChar(*(++strP));  

        checkSizeTemp += HEXLineData->address >> 8;
        checkSizeTemp += HEXLineData->address & 0xff;

        transformTemp[0] = (ConvertHexChar(*(++strP))<<4);
        transformTemp[0] |= (ConvertHexChar(*(++strP)));
        if(transformTemp[0] > (uint8_t)HEX_SLA){
            HEXLineData->Type = HEX_UNKNOW;
            return HEX_FORMAT_ERROR;
        }else{
            HEXLineData->Type = (em_HEXType)transformTemp[0];
            checkSizeTemp += HEXLineData->Type;
        }
        if(HEX_ELA == HEXLineData->Type){
            HEXLineData->baseAddr = ConvertHexChar(*(++strP));
            i = (HEXLineData->dataLen*2)-1;
            while (i--)
            {
                HEXLineData->baseAddr <<=4;
                HEXLineData->baseAddr |= ConvertHexChar(*(++strP));
            }
            checkSizeTemp += HEXLineData->baseAddr >> 8 & 0xff;
            checkSizeTemp += HEXLineData->baseAddr & 0xff;
        }else if(HEX_DATA == HEXLineData->Type){
            for (i = 0; i < HEXLineData->dataLen; i++)
            {
                HEXLineData->data[i] = (ConvertHexChar(*(++strP))<<4);
                HEXLineData->data[i] |= (ConvertHexChar(*(++strP)));
                checkSizeTemp += HEXLineData->data[i];
            }
        }else if(HEX_END == HEXLineData->Type){
            ;
        }else if(HEX_SLA == HEXLineData->Type){
        	for(i = 0; i < HEXLineData->dataLen; i++)
        	{
        		HEXLineData->data[i] = (ConvertHexChar(*(++strP))<<4);
        		HEXLineData->data[i] |= (ConvertHexChar(*(++strP)));
        		checkSizeTemp += HEXLineData->data[i];
        	}
        }
        
        HEXLineData->checkCode = (ConvertHexChar(*(++strP))<<4);
        HEXLineData->checkCode |= (ConvertHexChar(*(++strP)));
        if(HEXLineData->checkCode == (uint8_t)(0x100 - (checkSizeTemp & 0xff))){
            return HEX_NO_ERROR;
        }else{
            fprintf(USART2_STREAM,"--hex check error:%x,%x\r\n",HEXLineData->checkCode,checkSizeTemp);
            return HEX_VERIFY_ERROR;
        }
    }else{
        return HEX_FORMAT_ERROR;
    }
}





/*
//测试用例
#include <stdio.h>

#include <string.h>
#include <stdint.h>
#include <stdlib.h>

typedef enum{
    S19_NO_ERROR = 0,
    S19_FORMAT_ERROR = -1,
    S19_TYPE_ERROR = -2,
    S19_VERIFY_ERROR = -3,
    S19_LENGHT_ERROR = -4,
}S19ErrCode;

typedef enum{
    S0 = 0,
    S1,
    S2,
    S3,
    S5,
    S7,
    S8,
    S9,
    S_UNKNOW
}em_S19Type;

typedef struct 
{
    em_S19Type Type;
    uint32_t address;
    uint8_t count;
    uint8_t data[100];
    uint8_t checkSumCode;
    uint8_t dataLen;
}str_S19LineData;

void initS19Data(str_S19LineData *str_S19LineData){
    str_S19LineData->address = 0;
    str_S19LineData->checkSumCode = 0;
    str_S19LineData->count = 0;
    memset(str_S19LineData->data,0x00,sizeof(str_S19LineData->data));
    str_S19LineData->dataLen = 0;
    str_S19LineData->Type = S_UNKNOW;
}

char ConvertHexChar(const char ch)
{
    if((ch >= '0') && (ch <= '9'))
        return (ch-0x30);
    else if((ch >= 'A') && (ch <= 'F'))
        return ((ch-'A')+10);
    else if((ch >= 'a') && (ch <= 'f'))
        return ((ch-'a')+10);
    else return (-1);
}


S19ErrCode validateS19String(const char* s19String, unsigned int strLen,str_S19LineData *str_S19LineData){
    uint16_t i,j;
    uint16_t readSize = 0;
    const char s19TypeTable[8][3] = {"S0","S1","S2","S3","S5","S7","S8","S9"};
    uint8_t transformTemp[8] = {0};
    uint8_t addrSize = 0;
    uint8_t countSize = 0;
    const char *strP = NULL;
    uint16_t checkSizeTemp = 0;
    uint8_t getCountLoopCount = 0;
    strP = s19String;
    initS19Data(str_S19LineData);
    transformTemp[0] = *strP;
    
    if(!strcmp((const char*)transformTemp,"S")){
        fprintf(USART2_STREAM,"get s19 code:%s\n",s19String);
        memset(transformTemp,0x00,sizeof(transformTemp));
        memcpy(transformTemp,strP,2);
        fprintf(USART2_STREAM,"get s19 Type:%s\n",transformTemp);
        for (i = 0; i < 8; i++)
        {
            fprintf(USART2_STREAM,"Type%d:%s\n",i,s19TypeTable[i]);
            if(!strcmp((const char*)transformTemp,s19TypeTable[i])){
                str_S19LineData->Type = (em_S19Type)i;
                break;
            }
        }
        fprintf(USART2_STREAM,"s19 Type:%d\n",str_S19LineData->Type);
        if(i == 8){
            str_S19LineData->Type = S_UNKNOW;
            return S19_TYPE_ERROR;
        }
        strP+=2;
        // memset(transformTemp,0x00,sizeof(transformTemp));
        // memcpy(transformTemp,strP,2);
        countSize =  ConvertHexChar(*strP)<<4;
        countSize |= ConvertHexChar(*(++strP));
        fprintf(USART2_STREAM,"s19 count:%x\n",countSize);
        if(countSize > 0 && countSize<128){
            str_S19LineData->count = countSize;
            checkSizeTemp += (str_S19LineData->count) & 0xff;
            fprintf(USART2_STREAM,"checkSizeTemp:%x\n",checkSizeTemp);
        }else{
            return S19_LENGHT_ERROR;
        }
        //addr
        if(str_S19LineData->Type == S0){
            fprintf(USART2_STREAM,"this len is s01\n");
            str_S19LineData->address = 0;
        }else if(S1 == str_S19LineData->Type || S5 == str_S19LineData->Type || S9 == str_S19LineData->Type){
            
            str_S19LineData->address = (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
            str_S19LineData->address <<= 8;
            str_S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
            
            checkSizeTemp += (str_S19LineData->address >>8) & 0xff;
            checkSizeTemp += (str_S19LineData->address) & 0xff;
            getCountLoopCount = str_S19LineData->count-3;
            fprintf(USART2_STREAM,"s19 address:%x\n",str_S19LineData->address);

        }else if(S2 == str_S19LineData->Type || S8 == str_S19LineData->Type){

            str_S19LineData->address = (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
            str_S19LineData->address <<= 8;
            str_S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
            str_S19LineData->address <<= 8;
            str_S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
    
    
            checkSizeTemp += (str_S19LineData->address >>16) & 0xff;
            checkSizeTemp += (str_S19LineData->address >>8) & 0xff;
            checkSizeTemp += (str_S19LineData->address) & 0xff;
            getCountLoopCount = str_S19LineData->count-4;
            fprintf(USART2_STREAM,"s19 address:%x\n",str_S19LineData->address);

        }else if (S3 == str_S19LineData->Type || S7 == str_S19LineData->Type){

            str_S19LineData->address = (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
            str_S19LineData->address <<= 8;
            str_S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
            str_S19LineData->address <<= 8;
            str_S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
            str_S19LineData->address <<= 8;
            str_S19LineData->address |= (ConvertHexChar(*(++strP))<<4);
            str_S19LineData->address |= ConvertHexChar(*(++strP));
    
            checkSizeTemp += (str_S19LineData->address >>24) & 0xff;
            checkSizeTemp += (str_S19LineData->address >>16) & 0xff;
            checkSizeTemp += (str_S19LineData->address >>8) & 0xff;
            checkSizeTemp += (str_S19LineData->address) & 0xff;
            getCountLoopCount = str_S19LineData->count-5;
            fprintf(USART2_STREAM,"s19 address:%x\n",str_S19LineData->address);
        }
        fprintf(USART2_STREAM,"this len is s:%d\n",str_S19LineData->Type);
        fprintf(USART2_STREAM,"s19 getCountLoopCount:%d\n",getCountLoopCount);
        fprintf(USART2_STREAM,"data:");
        for (i = 0; i < getCountLoopCount; i++)
        {
            str_S19LineData->data[i] = ConvertHexChar(*(++strP))<<4;
            str_S19LineData->data[i] |= ConvertHexChar(*(++strP));
            fprintf(USART2_STREAM,"%02x",str_S19LineData->data[i]);
            checkSizeTemp += str_S19LineData->data[i];
        }
        
        str_S19LineData->checkSumCode = (ConvertHexChar(*(++strP))<<4);
        str_S19LineData->checkSumCode |= ConvertHexChar(*(++strP));
        fprintf(USART2_STREAM,"\r\nthis checkSizeTemp is s:%x\n",checkSizeTemp);
        fprintf(USART2_STREAM,"this checkSumCode is s:%x\n",str_S19LineData->checkSumCode);
        if(str_S19LineData->checkSumCode != (0xff - (checkSizeTemp & 0xff))){
            fprintf(USART2_STREAM,"check err:%x\n",(0xff - (checkSizeTemp & 0xff)));
            return S19_VERIFY_ERROR;
            
        }else{
            fprintf(USART2_STREAM,"check ok:%x\n",(0xff - (checkSizeTemp & 0xff)));
            return S19_NO_ERROR;
        }
    }else{
        return S19_FORMAT_ERROR;
    }
    return 0;
}



int main(int argc, char **argv) {
    char *s19code = "S21401221005E00123FB7002E00123FB70DEE0DDE058\r\n";
    str_S19LineData S19LineData;
    validateS19String(s19code,strlen(s19code),&S19LineData);
    
	fprintf(USART2_STREAM,"Hello, World!\n");
}

//hex

int validateHEXString(const char* s19String, unsigned int strLen,str_HEXLineData *HEXLineData){
    uint16_t i,j;
    uint16_t readSize = 0;
    uint8_t transformTemp[8] = {0};
    uint8_t addrSize = 0;
    uint8_t countSize = 0;
    const char *strP = NULL;
    uint16_t checkSizeTemp = 0;
    uint8_t getCountLoopCount = 0;
    strP = s19String;
    initHEXData(HEXLineData);
    transformTemp[0] = *strP;
    
    if(!strcmp((const char*)transformTemp,":")){
        fprintf(USART2_STREAM,"get hex code:%s\n",s19String);
        strP++;
        countSize =  ConvertHexChar(*strP)<<4;
        countSize |= ConvertHexChar(*(++strP));
        HEXLineData->dataLen = countSize;
        checkSizeTemp = countSize;
        fprintf(USART2_STREAM,"checkSizeTemp:%x\n",checkSizeTemp);
        fprintf(USART2_STREAM,"HEXLineData->dataLen:%x\n",HEXLineData->dataLen);

        HEXLineData->address = (ConvertHexChar(*(++strP))<<4);
        HEXLineData->address |= ConvertHexChar(*(++strP));
        HEXLineData->address <<= 8;
        HEXLineData->address |= (ConvertHexChar(*(++strP))<<4);
        HEXLineData->address |= ConvertHexChar(*(++strP));  
        fprintf(USART2_STREAM,"HEXLineData->address:%x\n",HEXLineData->address);

        checkSizeTemp += HEXLineData->address >> 8;
        fprintf(USART2_STREAM,"checkSizeTemp:%x\n",checkSizeTemp);
        checkSizeTemp += HEXLineData->address & 0xff;
        fprintf(USART2_STREAM,"checkSizeTemp:%x\n",checkSizeTemp);

        transformTemp[0] = (ConvertHexChar(*(++strP))<<4);
        transformTemp[0] |= (ConvertHexChar(*(++strP)));
        if(transformTemp[0] > (uint8_t)HEX_SLA){
            HEXLineData->Type = HEX_UNKNOW;
            return HEX_FORMAT_ERROR;
        }else{
            HEXLineData->Type = (em_HEXType)transformTemp[0];
            checkSizeTemp += HEXLineData->Type;
            fprintf(USART2_STREAM,"checkSizeTemp:%x\n",checkSizeTemp);
            fprintf(USART2_STREAM,"HEXLineData->Type:%x\n",HEXLineData->Type);
        }
        
        // if(HEX_ELA == HEXLineData->Type){
        //     HEXLineData->baseAddr = ConvertHexChar(*(++strP));
        //     i = (HEXLineData->dataLen*2)-1;
        //     while (i--)
        //     {
        //         HEXLineData->baseAddr <<=4;
        //         HEXLineData->baseAddr |= ConvertHexChar(*(++strP));
        //     }
        // }
        for (i = 0; i < HEXLineData->dataLen; i++)
        {
            HEXLineData->data[i] = (ConvertHexChar(*(++strP))<<4);
            HEXLineData->data[i] |= (ConvertHexChar(*(++strP)));
            checkSizeTemp += HEXLineData->data[i];
            fprintf(USART2_STREAM,"%x-",HEXLineData->data[i]);
            fprintf(USART2_STREAM,"checkSizeTemp:%x\n",checkSizeTemp);
        }
        HEXLineData->checkCode = (ConvertHexChar(*(++strP))<<4);
        HEXLineData->checkCode |= (ConvertHexChar(*(++strP)));
        if(HEXLineData->checkCode == (0x100 - (checkSizeTemp & 0xff))){
            fprintf(USART2_STREAM,"\ncheck ok:%x\n",(0x100 - (checkSizeTemp & 0xff)));
            return HEX_NO_ERROR;
        }else{
            fprintf(USART2_STREAM,"\ncheck no ok:%x\n",(0x100 - (checkSizeTemp & 0xff)));
            return HEX_VERIFY_ERROR;
        }
    }else{
        fprintf(USART2_STREAM,"HEX_FORMAT_ERROR\n");
        return HEX_FORMAT_ERROR;
    }
    return HEX_FORMAT_ERROR;    
}



int main(int argc, char **argv) {
    char *hexcode = ":20FF600081B081A038B0DAC178FF9AF103F08150814038509810DB0088202B2B3D10F6F5E4\r\n";
    str_HEXLineData HEXLineData;
    validateHEXString(hexcode,strlen(hexcode),&HEXLineData);
    
	fprintf(USART2_STREAM,"Hello, World!\n");
}


*/
